package com.hnkywl.sts.action.zjgl;

import com.hnkywl.sts.entity.zjgl.Yypf;
import com.hnkywl.sts.service.zjgl.YypfService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 说明：
 * 包:        com.hnkywl.sts.action.zjgl
 * 类描述:    异议赔付Action类
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 */
@Namespace("/zjgl/yypf")
public class YypfAction extends SimpleActionSupport {
    private YypfService yypfService;
    //合同编号
    private String htbm;
    //id
    private Long yypfId;
    //实体类实例化
    private Yypf yypf;
    private int page;
    //分页组件 页面大小
    private int rows = 10;

    @Action("yypfList")
    public void yypfList() {
        this.renderJson(this.yypfService.findAllYypf(htbm,page, rows));
    }

    @Action("yypf_content")
    public String yypf_content() {
        //进入update页面
        if (yypfId != null) {
            yypf = yypfService.findYypfDetail(yypfId);
        } else {
            yypf = new Yypf();
        }
        return SUCCESS;
    }

    /**
     * 增加异议赔付
     */
    @Action("add_yypf")
    public void addYypf() {
        try {
            this.yypfService.addYypf(yypf);
            renderText("{\"statusCode\":\"200\", \"message\":\"添加一条异议赔付记录成功！\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 修改异议赔付
     */
    @Action("update_yypf")
    public void updateYypf() {
        try {
            this.yypfService.updateYypf(yypf, yypfId);
            renderText("{\"statusCode\":\"200\",\"message\":\"修改一条异议赔付记录成功！\", \"operationType\":\"update\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 删除
     */
    @Action("del_yypf")
    public void del_yypf() {
        try {
            this.yypfService.delYypf(yypfId);
            renderText("{\"statusCode\":\"200\",\"message\":\"删除一条异议赔付记录成功！\", \"operationType\":\"update\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 下拉合同的查询分页
     */
    @Action("xlhtList")
    public void xlhtList() {
        renderJson(this.yypfService.findXlht(page, rows));
    }

    @Autowired
    public void setYypfService(YypfService yypfService) {
        this.yypfService = yypfService;
    }

    public String getHtbm() {

        return htbm;
    }

    public void setHtbm(String htbm) {
        this.htbm = htbm;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public Long getYypfId() {
        return yypfId;
    }

    public void setYypfId(Long yypfId) {
        this.yypfId = yypfId;
    }

    public Yypf getYypf() {
        return yypf;
    }

    public void setYypf(Yypf yypf) {
        this.yypf = yypf;
    }
}
